import { defineStore } from 'pinia';
import { ref } from 'vue';
import { request } from '@/utils/request';
export const useCartStore = defineStore(
  'cart',
  () => {
    // 购物车列表
    const list = ref<{}[]>([]);
    // 加入购物车
    const addCart = async (data: { skuId: string; count: number }) => {
      await request('POST', '/member/cart', data);
    };
    // 获取购物车列表
    const getCardList = async () => {
      const res = await request('get', '/member/cart');
      list.value = res.result;
    };
    return { list, addCart, getCardList };
  },
  {
    persist: true,
  }
);
